<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%
    String path = request.getContextPath();
%>
<!DOCTYPE HTML>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <title>垃圾分类查询</title>
    <link href="<%=path%>/static/css/all.css?94669434" rel="stylesheet" type="text/css">
    <!--[if IE]>
    <script>
        (function () {
            if (!/*@cc_on!@*/0) return;
            var e = "abbr,article,aside,audio,canvas,datalist,details,dialog,eventsource,figure,footer,header,hgroup,mark,menu,meter,nav,output,progress,section,time,video".split(','),
                    i = e.length;
            while (i--) {
                document.createElement(e[i])
            }
        })()
    </script>
    <![endif]-->
</head>
<body>
<header>
    <div id="topnav">
        <jsp:include page="/web/inc/header"/>
    </div>
</header>
<section>
    <div class="wrap">
        <div id="seach">
            <div id="logo"><a href="http://fenlicx.qinglab.cn" title="垃圾分类查询">分类查询</a></div>
            <div class="seach">
                    <input type="text" name="seach" class="seach_txt" id="seach" value="${requestScope.key}">
                    <input onclick="buttonClick()" type="submit" class="seach_bun" name="button" id="button" value="查询分类">
            </div>
        </div>
        <nav class="content-search">
        </nav>
        <article class="guild">
            <p>如果没有认可的的推荐分类，请点击推荐您认为对的分类，或者提问问题等待其他网站用户回答。</p>
            <div class="link">
                <a href="<%=path%>/web/question/list">问答</a>
                <a href="<%=path%>/web/garbage/addGarbageCheck">添加垃圾</a>
                <a id="addData" data-id="${sessionScope.userinfo.userType.id}" onclick="checkUser()" href="script:void(0);">添加垃圾数据</a>
            </div>
        </article>
    </div>
</section>
</div>
<footer>
    <div id="footer">
        <div id="footernav">
            <a href="#">返回顶部</a>
            <span>|</span>
            <a href="#">联系方式</a>
            <span>|</span>
            <a href="#">网站地图</a>
            <span>|</span>
            <a href="#">版权说明</a>
        </div>
        <div id="copyright">
            <p>copright qinglab轻网络实验室 <a href="HTTP://www.songshuo.com" target="_blank">宋硕设计工作室</a></p>
        </div>
    </div>
</footer>

<script src="<%=path%>/static/js/jquery-3.3.1.min.js"></script>
<script>
    //页面加载完成，获取文本框中的内容，调用搜索方法
    var key=null;
    var pageNum=null;
    $(function () {
        key=$(".seach_txt").val();
        initData(key,pageNum);
    })
    //按钮的点击事件
    function buttonClick() {
        key=$(".seach_txt").val();
        if(key.trim()=="")alert("请输入搜索内容");
        else{
            initData(key,pageNum)
        }

    }
    //利用ajax更新搜索内容
    function initData(key, pageNum) {
        $.ajax({
            url: "<%=path%>/web/garbage/searchData",
            async: false,
            data: {key: key, pageNum: pageNum},
            type: "GET",
            success: function (data) {
                $(".content-search").html(data);
            }
        })
    }

    $(function () {
        $(".content-search").on("click", ".pageList a", function () {
            pageNum = $(this).html();
            key=$(".seach_txt").val();
            initData(key,pageNum);
            $("a[id=" + pageNum + "]").css("color","#87CEEB");

        });
    })

    //判断用户身份
    function checkUser() {
        window.event.returnValue=false;
        var id=$("#addData").data("id");
        if(id=="")
        {
            window.location.href="<%=path%>/web/userinfo/login";
        }
        else
        {
            if(id==3)
            {
                window.location.href="<%=path%>/web/garbage/addData";

            }
            else {
                layer.msg("您没有权限添加数据",{icon:5});
            }
        }
    }
</script>
</body>
</html>
